package com.waiting.rocket.listener;

import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

@Component
@RocketMQMessageListener(topic = "sell",consumerGroup = "order-consumer")
public class OrderListener implements RocketMQListener<String> {

    @Autowired
    RocketMQTemplate rocketMQTemplate;

    @Override
    public void onMessage(String userInfo) {

        System.out.println("===收到消息=== " + userInfo + " ===== 扣除資料庫庫存");

        // 發送延遲隊列 30 秒 檢查
        rocketMQTemplate.syncSend("overtime", MessageBuilder.withPayload(userInfo).build(),2000,4);

    }
}
